import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'

/**
 * Note: sub-menu only appear when route children.length >= 1
 * Detail see: https://panjiachen.github.io/vue-element-admin-site/guide/essentials/router-and-nav.html
 *
 * hidden: true                   if set true, item will not show in the sidebar(default is false)
 * alwaysShow: true               if set true, will always show the root menu
 *                                if not set alwaysShow, when item has more than one children route,
 *                                it will becomes nested mode, otherwise not show the root menu
 * redirect: noRedirect           if set noRedirect will no redirect in the breadcrumb
 * name:'router-name'             the name is used by <keep-alive> (must set!!!)
 * meta : {
    roles: ['admin','editor']    control the page roles (you can set multiple roles)
    title: 'title'               the name show in sidebar and breadcrumb (recommend set)
    icon: 'svg-name'/'el-icon-x' the icon show in the sidebar
    breadcrumb: false            if set false, the item will hidden in breadcrumb(default is true)
    activeMenu: '/example/list'  if set path, the sidebar will highlight the path you set
  }
 */

/**
 * constantRoutes
 * a base page that does not have permission requirements
 * all roles can be accessed
 */
export const constantRoutes = [
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },

  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },

  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    children: [{
      path: 'dashboard',
      name: 'Dashboard',
      component: () => import('@/views/dashboard/index'),
      meta: { title: '首页' }
    }]
  },

  {
    path: '/in-storage',
    component: Layout,
    redirect: '/in-storage/register',
    name: 'Instorage',
    meta: { title: '物资入库' },
    children: [
      {
        path: 'register',
        component: () => import('@/views/in-storage/register/index'),
        name: 'Register',
        meta: { title: '采购登记' }
      },
      {
        path: 'examine',
        component: () => import('@/views/in-storage/examine/index'),
        name: 'Examine',
        meta: { title: '审核入库' }
      }
    ]
  },

  {
    path: '/retrieval',
    component: Layout,
    redirect: '/retrieval/receive',
    name: 'Retrieval',
    meta: { title: '物资出库' },
    children: [
      {
        path: 'receive',
        component: () => import('@/views/retrieval/receive/index'),
        name: 'Receive',
        meta: { title: '部门领用' }
      },
      {
        path: 'lend',
        component: () => import('@/views/retrieval/lend/index'),
        name: 'Lend',
        meta: { title: '物资借出' }
      },
      {
        path: 'lendexamine',
        component: () => import('@/views/retrieval/lendexamine/index'),
        name: 'Lendexamine',
        meta: { title: '借出审核' }
      }
    ]
  },

  {
    path: '/handle',
    component: Layout,
    redirect: '/handle/inventory',
    name: 'Handle',
    meta: { title: '物资处理' },
    children: [
      {
        path: 'inventory',
        component: () => import('@/views/handle/inventory/index'),
        name: 'Inventory',
        meta: { title: '库存盘点' }
      },
      {
        path: 'frmloss',
        component: () => import('@/views/handle/frmloss/index'),
        name: 'Frmloss',
        meta: { title: '部门报损' }
      }
    ]
  },

  {
    path: '/query',
    component: Layout,
    redirect: '/query/orderquery',
    name: 'Query',
    meta: { title: '查询统计' },
    children: [
      {
        path: 'orderquery',
        component: () => import('@/views/query/orderquery/index'),
        name: 'Orderquery',
        meta: { title: '采购单查询' }
      },
      {
        path: 'instorageorder',
        component: () => import('@/views/query/instorageorder/index'),
        name: 'Instorageorder',
        meta: { title: '入库查询' }
      },
      {
        path: 'departmentorder',
        component: () => import('@/views/query/departmentorder/index'),
        name: 'Departmentorder',
        meta: { title: '部门领用查询' }
      },
      {
        path: 'summary',
        component: () => import('@/views/query/summary/index'),
        name: 'Summary',
        meta: { title: '部门领用汇总' }
      }
    ]
  },

  {
    path: '/basicinfo',
    component: Layout,
    redirect: '/basicinfo/users',
    name: 'Basicinfo',
    meta: { title: '基础信息' },
    children: [
      {
        path: 'suppliermanage',
        component: () => import('@/views/basicinfo/suppliermanage/index'),
        name: 'Suppliermanage',
        meta: { title: '供应商管理' }
      },
      {
        path: 'materialmanage',
        component: () => import('@/views/basicinfo/materialmanage/index'),
        name: 'Materialmanage',
        meta: { title: '物资管理' }
      },
      {
        path: 'departmentmanage',
        component: () => import('@/views/basicinfo/departmentmanage/index'),
        name: 'Departmentmanage',
        meta: { title: '部门管理' }
      }
    ]
  },

  {
    path: '/manage',
    component: Layout,
    redirect: '/manage/users',
    name: 'Manage',
    meta: { title: '系统管理' },
    children: [
      {
        path: 'users',
        component: () => import('@/views/manage/users/index'),
        name: 'Users',
        meta: { title: '用户管理' }
      },
      {
        path: 'editUser',
        component: () => import('@/views/manage/editUser/index'),
        name: 'EditUser'
      },
      {
        path: 'addUser',
        component: () => import('@/views/manage/addUser/index'),
        name: 'AddUser'
      }
    ]
  },

  

  { path: '*', redirect: '/404', hidden: true }
]

const createRouter = () => new Router({
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

const router = createRouter()

export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
